

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/notebook.ico">
  <link rel="icon" href="/img/notebook.ico">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
  <title>Shell脚本部署jar包 - xulinglin</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10.7.2/styles/monokai-sublime.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css" />
  



<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->

  
<link rel="stylesheet" href="/css/diy/shubiao.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/bynotes/texiao/source/css/toubudaziji.css">



  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.8.11","typing":{"enable":true,"typeSpeed":70,"cursorChar":"","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.4.0"></head>


<body>
  <header style="height: 30vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>笑语</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                目录
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/img_1.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.5)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="Shell脚本部署jar包">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2021-06-04 14:36" pubdate>
        2021年6月4日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      363 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      6
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Shell脚本部署jar包</h1>
            
            <div class="markdown-body">
              <p class="note note-info">
Linux 下部署 jar的脚本,以及一些采用的设置参数。
</p>

<h2 id="1-目录包"><a href="#1-目录包" class="headerlink" title="1. 目录包"></a>1. 目录包</h2><div class="hljs code-wrapper"><pre><code class="hljs Python"><span class="hljs-string">&quot;脚本&quot;</span>   <span class="hljs-string">&quot;配置&quot;</span>   <span class="hljs-string">&quot;包&quot;</span>   <span class="hljs-string">&quot;日志&quot;</span>
 <span class="hljs-built_in">bin</span>     conf      lib     logo

<span class="hljs-string">&quot;给启动权限&quot;</span>
chmod a+x startup.sh 

<span class="hljs-string">&quot;查看端口是否可用&quot;</span>
netstat -anp|grep <span class="hljs-number">3306</span>

<span class="hljs-string">&quot;看日志&quot;</span>
tail -fn <span class="hljs-number">200</span> **.log</code></pre></div>
<h2 id="2-startup-sh-启动脚本"><a href="#2-startup-sh-启动脚本" class="headerlink" title="2. startup.sh(启动脚本)"></a>2. startup.sh(启动脚本)</h2><div class="hljs code-wrapper"><pre><code class="hljs Bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment">## confirm app dir.</span>
DIR=$(<span class="hljs-built_in">cd</span> `dirname <span class="hljs-variable">$0</span>`; <span class="hljs-built_in">cd</span> ..; <span class="hljs-built_in">pwd</span>)

<span class="hljs-comment">## confirm conf dir.</span>
CONF=<span class="hljs-variable">$DIR</span>/conf

<span class="hljs-comment">## confirm lib.</span>
JAR=<span class="hljs-variable">$DIR</span>/lib/spax-ec-pay-service-1.0.0.jar

<span class="hljs-comment">## profile</span>
PROFILE=<span class="hljs-built_in">test</span>

<span class="hljs-comment">## jvm配置参数</span>
JVM=<span class="hljs-string">&quot;-Xms1024m -Xmx1024m -Xmn512m -Xss256k -XX:NewRatio=4 -XX:SurvivorRatio=4 -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m -XX:-UseAdaptiveSizePolicy -XX:TargetSurvivorRatio=90 -XX:MaxTenuringThreshold=15 -XX:+UseConcMarkSweepGC -server&quot;</span>

<span class="hljs-comment">## SpringBoot 2.0 版本以上 -Dspring.config.additional-location 加载外部配置文件,以下的用 -Dspring.config.location </span>
nohup java <span class="hljs-variable">$&#123;JVM&#125;</span> -jar <span class="hljs-variable">$JAR</span> -Dspring.config.additional-location=<span class="hljs-variable">$CONF</span>/ -Dspring.profiles.active=<span class="hljs-variable">$PROFILE</span> &gt; /dev/null 2&gt;&amp;1 &amp;
</code></pre></div>

<h2 id="3-shutdown-sh-关闭脚本"><a href="#3-shutdown-sh-关闭脚本" class="headerlink" title="3. shutdown.sh(关闭脚本)"></a>3. shutdown.sh(关闭脚本)</h2><div class="hljs code-wrapper"><pre><code class="hljs Bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment">## indexOf function.</span>
<span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">indexOf</span></span>()&#123;
  arr=<span class="hljs-variable">$1</span>

  <span class="hljs-built_in">local</span> index=1
  <span class="hljs-built_in">local</span> e

  <span class="hljs-keyword">for</span> e <span class="hljs-keyword">in</span> <span class="hljs-variable">$&#123;arr[*]&#125;</span>; <span class="hljs-keyword">do</span>
    <span class="hljs-keyword">if</span> [ <span class="hljs-variable">$2</span> = <span class="hljs-string">&quot;<span class="hljs-variable">$e</span>&quot;</span> ]; <span class="hljs-keyword">then</span>
      <span class="hljs-built_in">return</span> <span class="hljs-variable">$index</span>
    <span class="hljs-keyword">else</span>
      (( index= index+1 ))
    <span class="hljs-keyword">fi</span>
  <span class="hljs-keyword">done</span>
  <span class="hljs-built_in">return</span> 0
&#125;

JPS=`/opt/java/jdk1.8/bin/jps`

attr=(<span class="hljs-variable">$JPS</span>)

indexOf <span class="hljs-string">&quot;<span class="hljs-variable">$&#123;attr[*]&#125;</span>&quot;</span> **名称.jar

ret=$?

<span class="hljs-keyword">if</span> [ <span class="hljs-variable">$ret</span> != 0 ]; <span class="hljs-keyword">then</span>
  (( ret=<span class="hljs-variable">$ret</span>-2 ))
  process=<span class="hljs-variable">$&#123;attr[$ret]&#125;</span>
  <span class="hljs-built_in">echo</span> <span class="hljs-string">&#x27;kill process &#x27;</span><span class="hljs-variable">$process</span>

  <span class="hljs-built_in">kill</span> -9 <span class="hljs-variable">$process</span>
<span class="hljs-keyword">fi</span>

<span class="hljs-built_in">echo</span> <span class="hljs-string">&quot;finish stop!&quot;</span></code></pre></div>

<h2 id="4-PS-查询-pid"><a href="#4-PS-查询-pid" class="headerlink" title="4. PS 查询 pid"></a>4. PS 查询 pid</h2><div class="hljs code-wrapper"><pre><code class="hljs Bash"><span class="hljs-meta">#!/bin/bash</span>

JARFILE=<span class="hljs-string">&#x27;名称.jar&#x27;</span>
<span class="hljs-built_in">echo</span> <span class="hljs-variable">$JARFILE</span>
ID=`ps -ef | grep <span class="hljs-string">&quot;<span class="hljs-variable">$JARFILE</span>&quot;</span> | grep -v <span class="hljs-string">&quot;grep&quot;</span> | awk <span class="hljs-string">&#x27;&#123;print $2&#125;&#x27;</span>`
<span class="hljs-built_in">echo</span> <span class="hljs-variable">$ID</span>
<span class="hljs-keyword">for</span> id <span class="hljs-keyword">in</span> <span class="hljs-variable">$ID</span>
<span class="hljs-keyword">do</span>
<span class="hljs-built_in">kill</span> -9 <span class="hljs-variable">$id</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">&quot;kill process <span class="hljs-variable">$id</span>&quot;</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">&quot;finish stop!&quot;</span></code></pre></div>

<h2 id="5-restart-sh-重新启动"><a href="#5-restart-sh-重新启动" class="headerlink" title="5. restart.sh(重新启动)"></a>5. restart.sh(重新启动)</h2><div class="hljs code-wrapper"><pre><code class="hljs Bash"><span class="hljs-meta">#!/bin/bash</span>

sh shutdown.sh

sh startup.sh</code></pre></div>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Linux/">Linux</a>
                    
                      <a class="hover-with-bg" href="/tags/jar%E9%83%A8%E7%BD%B2/">jar部署</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2021/06/04/es/ElasticSearch1.0/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">ElasticSearch 集群的工作原理</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2021/06/04/java/synchronized1.0/">
                        <span class="hidden-mobile">深入理解 synchronized 原理</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
              <!-- Comments -->
              <article class="comments" id="comments" lazyload>
                
                  
                
                
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://cdn.jsdelivr.net/gh/HCLonely/Valine@latest/dist/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"BmWJPSifebgqliaA9sdhmII7-gzGzoHsz","appKey":"HvFu44h5vVRRYuQIg6uNJkKR","placeholder":"说点什么","path":"window.location.pathname","avatar":"retro","meta":["nick","mail","link"],"pageSize":10,"lang":"zh-CN","highlight":true,"recordIP":false,"serverURLs":"https://bmwjpsif.lc-cn-n1-shared.com","emojiCDN":null,"emojiMaps":null,"enableQQ":false,"requiredFields":[]},
          {
            el: "#valine",
            path: window.location.pathname,
            master: "",
            friends: "",
            tagMeta: ["博主","友人","访客"]
          }
        )
        new Valine(options);
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


              </article>
            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  <script  src="https://cdn.jsdelivr.net/npm/tocbot@4.12.3/dist/tocbot.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4.3.1/anchor.min.js" ></script>



  <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js" ></script>



  <script  src="/js/local-search.js" ></script>






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2.0.12/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
      typing(title)
      
    })(window, document);
  </script>














  
<script src="/js/diy/timeDate.js"></script>



<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
